<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
    div{
        margin-top: 30px;
        width: 200px;
        height: 100px;
        background-color: green;
        position: absolute;
        left: 50px;
    }
    </style>
</head>

<body>
    <input type="button" value="移动到400" id="btn1">
    <input type="button" value="移动到800" id="btn2">
    <div id="dv"></div>
    <script src="common.js"></script>
    <script>
        //点击第一个按钮移动到400
        //点击第一个按钮移动到800
        my$("btn1").onclick = function () {
            var timeId = setInterval(function () {
                var current = my$("dv").offsetLeft;
                var step = 10;
                current += step;
                if(current<=400){
                    my$("dv").style.left=current+"px";
                }
                else{
                    clearInterval(timeId);
                }
                
            }, 20)
        }
        my$("btn2").onclick = function () {
            var timeId = setInterval(function () {
                var current = my$("dv").offsetLeft;
                var step = 10;
                current += step;
                if(current<=800){
                    my$("dv").style.left=current+"px";
                }
                else{
                    clearInterval(timeId);
                }
                
            }, 20)
        }
    </script>
</body>

</html>